/*----------------------------------------------
| noka select v1.0 www.97521.com                 |
| rebin 2014-01-15                             |
|---------------------------------------------*/
var nbox = Class.create({
    version: '1.0',
    initialize : function(cfg) {
    	this.cfg = cfg;					//配置信息
    	this.id=cfg.id; //id
    	this.rurl=cfg.rurl;
    	this.bheight=cfg.bheight;//弹出框高
    	this.bwidth=cfg.bwidth;//弹出框宽
    	this.lotype = cfg.lotype;
    	this.openfunction= cfg.openfunction;
    	this.closefunction = cfg.closefunction;
    	this.msg = cfg.msg || '';
    	this.htmlTemp = $(cfg.id).innerHTML;
    	this.showtitle = cfg.showtitle;
    	this.title = cfg.title;
    	this.stopclose = (undefined == cfg.stopclose?false:cfg.stopclose);
    	this.gridids = cfg.gridids;
    },
    show : function(){
    	this.selectEvent();
    },
    //===================绑定事件============================================================
    selectEvent : function(){
    	var self = this;
        var obj = $(self.id);
        if('html'!=self.lotype){
        	$(self.id).innerHTML='';
        }
        try{
        	$(self.id).setStyle({display:'none',overflow:'auto'});
        	$(self.id).hide();
        	$(self.id).removeClassName('initboxdiv');
        	$(self.id+'_boxid_tmask').removeClassName('initboxdiv');
        	$(self.id+'_boxid_tcontent').removeClassName('initboxdiv');
        }catch(e){};
        //-------------显示事件-------------------------------------------------------------
        obj.show = function(cfg){
        	if('html'==self.lotype){
        		$(self.id).setStyle({display:''});
        	}
        	if(typeof cfg == "undefined"){
	    		if('iframe'==self.lotype)
	    			NokaBox.box.show({stopclose:self.stopclose,iframe:self.htmlTemp,boxid:self.id+'_boxid',autohide:0,fixed:false,title:self.title,showtitle:self.showtitle,width:self.bwidth,height:self.bheight,openjs:self.openfunction,closejs:self.closefunction});
	    		else if('html'==self.lotype){
	    			NokaBox.box.show({stopclose:self.stopclose,html:self.htmlTemp,boxid:self.id+'_boxid',autohide:0,fixed:false,cdiv:false,title:self.title,showtitle:self.showtitle,width:self.bwidth,height:self.bheight,openjs:function(){
	    				if(undefined!=self.gridids){
		    				for(var i=0;i<self.gridids.length;i++){
		    					try{
			    					if('true'==self.gridids[i].autosize){
			    						var theight =$(self.id+'_boxid_tite').getHeight();
			    						$(self.gridids[i].grid).setAutosize(self.gridids[i].autosize,self.gridids[i].autowidth);
			    						$(self.gridids[i].grid).setWidthHeihgt((self.bwidth-10)+'px',(self.bheight-theight)+'px');
			    						$(self.gridids[i].grid).setSize(0,self.bheight);
			    						$(self.gridids[i].grid).reinit();
			    					}
		    					}catch(e){}
	    					}
	    				}
	    				try{
	    					self.openfunction();
	    				}catch(e){}
	    			},closejs:self.closefunction});
	    		}else if('url'==self.lotype)
	    			NokaBox.box.show({stopclose:self.stopclose,url:self.htmlTemp,boxid:self.id+'_boxid',autohide:0,fixed:false,title:self.title,showtitle:self.showtitle,width:self.bwidth,height:self.bheight,openjs:self.openfunction,closejs:self.closefunction});
	    		else if('image'==self.lotype)
	    			NokaBox.box.show({stopclose:self.stopclose,image:self.htmlTemp,boxid:self.id+'_boxid',autohide:0,fixed:false,title:self.title,showtitle:self.showtitle,width:self.bwidth,height:self.bheight,openjs:self.openfunction,closejs:self.closefunction});
        	}else{
        		cfg.stopclose=self.stopclose;
        		NokaBox.box.show(cfg);
        	}
        	
        };
        //----------------------------------------------------------------------------------
        obj.hide = function(){
        	 try{NokaBox.box.hide();}catch(e){}
        };
    }
});